﻿using System;
using QLNet;
using p = FinPlusAnalytics.QLConvParser;
using u = FinPlusUtility.Utility;

namespace FinPlusAnalytics
{
    public class FloatingLegTrade : Trade
    {
        public string Id { get; private set; }
   
        //construct
        public FloatingLegTrade(string marketName, string cacheName, string id, double nominal, DateTime start, DateTime maturity, string payRec, string curveName, string index, 
            double spread,  string fltLegFrq, string fltLegConv, string fltLegDayCount, string holidays, bool endOfMonth = false)
        {
            Id = id;
            var market = Markets.Instance.GetMarket(marketName);
            var cache = Caches.Instance.GetCache(cacheName);
            var indx = market.GetIndex(index);
            var calendar = p.Calendar(holidays);
            var type = u.EnumParse<QLNet.FloatingLeg.Type>(p.PayRec(payRec));
		
            var schedule = new Schedule(start, maturity, new Period(p.Freq(fltLegFrq)), calendar, p.BizConv(fltLegConv), 
                p.BizConv(fltLegConv), DateGeneration.Rule.Forward, endOfMonth);

            Underlying = new FloatingLeg(type, nominal, schedule, indx, spread, p.DayCount(fltLegDayCount)); 

            cache.Add(id, this, curveName);
        }
    }
}
